package com.atguigu.search.thread;

import java.util.concurrent.*;

public class RejectThreadPoolDemo {
  public static class MyTask implements Runnable {

    @Override
    public void run() {
      System.out.println(System.currentTimeMillis() + ":Thread ID:" + Thread.currentThread().getId());
      try {
        Thread.sleep(100);
      } catch (InterruptedException e) {
        e.printStackTrace();
      }
    }
  }


  public static void main(String args[]) throws InterruptedException {
    MyTask myTask = new MyTask();

    ExecutorService executorService = new ThreadPoolExecutor(5, 5, 0L,
      TimeUnit.SECONDS, new LinkedBlockingDeque<>(10), Executors.defaultThreadFactory()
      , (r, executor) -> System.out.println(r.toString() + " is discard;" + executor.getCorePoolSize()));

    for (int i = 0; i < 100; i++) {
      executorService.submit(myTask);
      Thread.sleep(10);
    }
  }
}
